﻿using Furion.DependencyInjection;
using Furion.DynamicApiController;
using GWB.Application.Service.PlatForm.IBK;
using GWB.Core.Common;
using GWB.Core.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static GWB.Application.Service.PlatForm.IBK.IBKServer;

namespace GWB.Application.Service.PlatForm.Test
{
    public class Test1Server : ITest1Server, ITransient, IDynamicApiController
    {
       
        public void Test1(string carNo)
        {
            try
            {
                var url = "https://detail.zol.com.cn/xhr3_Subcate_Nav.html";
                Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add("User-Agent", "PostmanRuntime-ApipostRuntime/1.1.0");
                dic.Add("Cache-Control", "no-cache");
                dic.Add("Accept", "*/*");
                dic.Add("Accept-Encoding", "gzip, deflate, br");
                dic.Add("Connection", "keep-alive");
                dic.Add("Cookie", "acw_tc=2f6a1fee17022228296143618e45789a2db35dca662503fb0b729d71e6db17;key=kf463cOCOnr8zttLQ2z0jQ==;acw_tc=2f6a1fcd17016538368182593ec4d7d05cf9818218fb2d02d7f9d3a936a331; 66_sid=anbo_445100202308020312; key=kf463cOCOnr8zttLQ2z0jQ==; OperationCode=vng1gx6PntpB8zt+6d2BLYKx7kOT2aQsG3MvY4/Iv+gfPTVye+NtSw==; WxLoginInfo=0pj6j5u7Fi2YVK5y+xfNPTrQCkzy0aLQcIKIyoxH7lU8wr0e+WLlGyx60FqmdnuObsu0QA00E0LmtoBzsHPcqkyoBtU0+CfX+/BpjiqoOInZibmr/k5ftxqYOmKiUFNO7e3Owj068oGEhyPOjjlv7hV6ItYSrnkqlUwUcLDgOVk1YvPhRZY4rqDCOXjE6Srs6jdv+bB78+3C/W8soasZPw==; WapPay_UserInfo=DFXfRm4ivPDP1R6z7B++drld/jH0WTYOW0PdzMomQ+ZpWBPVzF5bNJFNg1lzz8lwJbFCVx7kykulAsvpFUGei+9KW1qCYJyiwDNWYb+VVHAqzrA6GtMEMvmHy+cz8x8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9M6P03NNGW5Xi3mY7ACxkkjAnIk1mp5boHeuitq0ISUeKUTxPqC9PRNS4oXiXeV8oiA5tZ4FyIAR1MmgXjzbaXK+fI6RDNHbNWOHmbJ72HwYSrNj0WNqNj5iX1qwexdgnOVIKQuGn5hbXpX9UyhvaGLygFvgntyBdWeujOanibePE4VrKfP4HFacekUOMYn1vfXCIZegtrsWoBQ2izkdPbiLeQyGYtYH+FRJyIxMCSzbfUiv86GbnE2DpzWdTd54Ml9wgEEMT/itZC8TZlIyqKkTjili29tBJ1jokaRyPRDuWojLZiZi2S/cBMe0axgItxQqRHUxnZ7dEGDifVjA7DnAz7rlNv3wJnuwZfC1WFwwauK+hw47ND6QsCxov97x3Idn9XRSJs+yOympZrobrVDyZsGzZFSyt/UHkJaOQHzRyW1PMHs4VZ2nckIj16K1dDZRxtV45sHqAPQPlpBokTWYkUUy/QNigyQ60krdmb/qNszgrT47DonBwzGvTEITCq3bncoHycqOpm1L3Z4YTxVb/7klvIQBppaY5zSHJPAbuQPoqwTIYrthrDTey2iveYaemh6CS9xUuNWG8GAcmGzS931hFVtopL7DMI8NIB6qwshMIpWUoFhhniSmfQpGgMAaViW6jKB6qK1d/Chlhxp2D1ZC7vKeifqdsgC3ObG0TOl5TiPHVwsReUAWRYO0e3m+eRlS1Wz40T8dvkUK7qPwWCc1R2V5skx+CLEBdT6epFlYupfwmVyHWBcaqnBJ9mTpUzynXRhsLoPFewDpHUuvcnah4HDzD7XLZ8zQFp/SPNb0mR0kylVL12sfayBZaumP5A==");
                var result = "";
                result = HttpHelper.HttpGet(url, "", dic, "application/x-www-form-urlencoded; charset=UTF-8");
                var html = HtmlAnalysis(result);

                var resData = new ValueEntity();

                resData = JsonConvert.DeserializeObject<ValueEntity>("{ \"CarNo\": \"粤B46789\", \"QueryTime\": \"2023/12/18 17:18:48\", \"ParkingName\": \"鹤山碧桂园2\", \"BeginTime\": \"2023-03-27 10:22:02\" }");
                AddTest(carNo);
            }
            catch (Exception e)
            {
                SqlSugarHelper.Db.Insertable<ErrorLogEntity>(new ErrorLogEntity()
                    {
                        CreateTime = DateTime.Now,
                        ErrorStr= e.Message,
                        Module=""
                    })
                    .ExecuteCommandAsync();
                throw;
            }

           
        }

        public void AddTest( string carNo)
        {
            SqlSugarHelper.Db.Updateable<CarNoModel>()
                .SetColumns(it => it.ImportTime == DateTime.Now)//SetColumns是可以叠加的 写2个就2个字段赋值
                .Where(it => it.CarNo==carNo)
                .ExecuteCommandAsync();
        }

        public string HtmlAnalysis(string html)
        {

            var result = "";
            if (html.IndexOf("strData") == -1)
            {
                return "-1";
            }

            try
            {
                // 正则表达式模式
                string pattern = @"<script>(.*?)</script>";
                // 创建正则表达式对象
                Regex regex = new Regex(pattern, RegexOptions.Singleline);
                // 查找匹配的结果
                MatchCollection matches = regex.Matches(html);

                // 正则表达式模式
                 pattern = @"<script>(.*?)</script>";
                // 创建正则表达式对象
                 regex = new Regex(pattern, RegexOptions.Singleline);
                // 查找匹配的结果
                 matches = regex.Matches(html);

                // 正则表达式模式
                 pattern = @"<script>(.*?)</script>";
                // 创建正则表达式对象
                 regex = new Regex(pattern, RegexOptions.Singleline);
                // 查找匹配的结果
                 matches = regex.Matches(html);

            }
            catch (Exception e)
            {
                throw new Exception("HtmlAnalysis_HTML解析错误");
            }


            return result;
        }
    }
}
